StupidBeauty
Read times:658Posted at:Mon May 28 02:49:53 2012
- no title specified

转载:解析QT 使用Sqlite存储读取文件

在QT中,要想将大块的数据以BLOB方式存储到SQLITE中去的话,可先将大块数据序列化到一个QByteArray中,再将该QByteArray像其它类型的数据一样bindValue到一个字段中。

http://mobile.51cto.com/symbian-273532.htm

亮点:

bool MyDatabase::StoreFile(QString FileName) { QSqlQuery query(db); QFile File(FileName); if(File.open(QIODevice::ReadOnly)){ QByteArray &tdata = File.readAll(); QByteArray data = qCompress(tdata,9); query.prepare("INSERT INTO files (id,filename,filecontent)" "VALUES(NULL,:filename,:filecontent)"); query.bindValue(":filename", FileName); query.bindValue(":filecontent", data); if(!query.exec()) { qDebug()<<query.lastError(); return false; } } else { return false; } return true; }

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands